﻿using System;
using System.Collections.Generic;
using System.Text;

namespace AbpPlusPlus.Commanding
{
    using System.Threading.Tasks;

    using Abp.Dependency;

    using MediatR;

    public interface ICommandBus : ITransientDependency
    {
        Task Send<TCommand>(TCommand command)
            where TCommand : IRequest;

        Task<TCommandResult> Send<TCommand, TCommandResult>(
            TCommand command)
            where TCommand:IRequest<TCommandResult>;
    }

    public class CommandBus:ICommandBus
    {
        private readonly IMediator _mediator;

        public CommandBus(IMediator mediator)
        {
            this._mediator = mediator;
        }

        public async Task Send<TCommand>(TCommand command)
            where TCommand : IRequest
        {
            await this._mediator.Send(command);
        }

        public async Task<TCommandResult> Send<TCommand, TCommandResult>(TCommand command)
            where TCommand : IRequest<TCommandResult>
        {
            return await this._mediator.Send(command);
        }
    }
    
}
